package org.brownflat.watergate.resources.mysql;

import org.brownflat.watergate.resources.MySqlUpgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0013ReviewState implements MySqlUpgrade {

    private static final int VERSION = 13;

    @Override
    public int getSequence() {
        return VERSION;
    }

    @Override
    public String getSql() {
        return "ALTER TABLE wgate_review_state ADD COLUMN (next_state int(11));\n" +
               "ALTER TABLE wgate_review_state ADD COLUMN (previous_state int(11));" +
               "UPDATE wgate_review_state set next_state=2 WHERE name='COMMENCED';\n" +
               "UPDATE wgate_review_state set next_state=3 WHERE name='COMPLETED';\n" +
               "UPDATE wgate_review_state set next_state=4 WHERE name='CLOSED';\n" +
               "UPDATE wgate_review_state set previous_state=3 WHERE name='ARCHIVED';\n" +
               "UPDATE wgate_review_state set previous_state=2 WHERE name='CLOSED';\n" +
               "UPDATE wgate_review_state set previous_state=1 WHERE name='COMPLETED';\n";
    }

    @Override
    public String getName() {
        return "Create review state sequence";
    }
}
